package com.example.skymallseckillproductapi.config;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * Web应用工具类
 */
@Configuration
public class WebAppUtils {

    /**
     * 向响应中写入JSON数据
     *
     * @param response HttpServletResponse对象
     * @param json JSON字符串
     * @throws IOException IO异常
     */
    public static void writeJson(HttpServletResponse response, String json) throws IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=utf-8");
        try (PrintWriter writer = response.getWriter()) {
            writer.print(json);
            writer.flush();
        }
    }
}